package com.gwnet.shop.controller.api;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.mybatis.core.page.TableDataInfo;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.shop.controller.MBaseController;
import com.gwnet.shop.domain.SysTenant;
import com.gwnet.shop.service.ISysTenantService;
import com.gwnet.shop.utils.AjaxResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 租户管理Controller
 * @author 张万鹏
 * @date 2024-07-25
 */
@RestController
@RequestMapping("/api/tenant")
public class SysTenantApiController extends MBaseController
{
    @Resource
    private ISysTenantService sysTenantService;

    /**
     * 查询租户管理列表
     */
    @SaCheckPermission("shop:tenant:list")
    @GetMapping("/list")
    public TableDataInfo list(SysTenant sysTenant)
    {
        startPage();
        List<SysTenant> list = sysTenantService.selectSysTenantList(sysTenant);
        return getDataTable(list);
    }

    /**
     * 查询租户管理列表 (营业中的)
     */
    @SaCheckPermission("shop:tenant:list")
    @GetMapping("/list/opening")
    public TableDataInfo listOpening(SysTenant sysTenant)
    {
        startPage();
        List<SysTenant> list = sysTenantService.selectSysTenantListOpening(sysTenant);
        return getDataTable(list);
    }

    /**
     * 查询 当前用户购买过商品的 租户列表
     */
    @SaCheckPermission("shop:tenant:list")
    @GetMapping("/list/buy")
    public TableDataInfo listBuy()
    {
        startPage();

        Long userId = LoginHelper.getUserId();
        List<SysTenant> list = sysTenantService.selectSysTenantListBuy(userId);
        return getDataTable(list);
    }

    /**
     * 获取租户管理详细信息
     */
    @SaCheckPermission("shop:tenant:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysTenantService.selectSysTenantById(id));
    }
}
